package com.cn.cxq.interceptor;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.cn.cxq.bean.User;
import com.cn.cxq.util.SQLUtil;

public class UtilsInterceptor extends HandlerInterceptorAdapter{

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		String sqlSource = "DB_01";//(String)request.getAttribute("sqlSource");
		
		User user = (User)request.getAttribute("user");
		if(user != null && sqlSource !=null && sqlSource.length() >0 && !sqlSource.equalsIgnoreCase("all")){
			Connection con = SQLUtil.getConnection(request, sqlSource);
			request.setAttribute("con", con);
			
		}
		return super.preHandle(request, response, handler);
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
		
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
	}
}
